package com.bigdata.service.mysql.impl;/**
 * Created by Administrator on 2019/8/23 0023.
 */

import com.bigdata.common.em.CommonEnum;
import com.bigdata.model.Result;
import com.bigdata.model.SearchModel;
import com.bigdata.mysql.dao.JkfwMenuPinyinMapper;
import com.bigdata.mysql.entity.JkfwMenu;
import com.bigdata.mysql.entity.JkfwMenuPinyin;
import com.bigdata.mysql.entity.JkfwMenuPinyinExample;
import com.bigdata.service.mysql.JkfwMenuPinyinService;
import com.bigdata.service.mysql.base.impl.BaseService;
import com.bigdata.utils.Pinyin4jUtils;
import com.bigdata.utils.StringUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @author lly
 * @description
 * @date 2019/8/23 0023
 **/
@Service
public class JkfwMenuPinyinServiceImpl extends BaseService<JkfwMenuPinyinMapper, JkfwMenuPinyin, JkfwMenuPinyinExample> implements JkfwMenuPinyinService {

    @Override
    public Result queryPage(SearchModel searchModel) {
        return null;
    }

    /**
     * @Author lly
     * @param: jkfwMenu
     * @Date 2019/8/26 0026
     * @Description 添加拼音表数据
     */
    @Override
    public void addPinyin(JkfwMenu jkfwMenu) {
        String qypy = Pinyin4jUtils.getPinyinToLowerCase(jkfwMenu.getName());
        String jp = Pinyin4jUtils.getPinyinJianPinToLowerCase(jkfwMenu.getName());
        List<String> qypys = StringUtil.splitList(qypy);
        List<String> jpys = StringUtil.splitList(jp);
        for (String py : qypys) {
            JkfwMenuPinyin pinyin = new JkfwMenuPinyin();
            pinyin.setId(UUID.randomUUID().toString().replace("-", ""));
            pinyin.setMenuid(jkfwMenu.getMenuId());
            pinyin.setPyzm(py);
            pinyin.setPyzmjx(CommonEnum.PinYinEnum.quanpin.getName());
            dao.insert(pinyin);
        }
        for (String py : jpys) {
            JkfwMenuPinyin pinyin = new JkfwMenuPinyin();
            pinyin.setId(UUID.randomUUID().toString().replace("-", ""));
            pinyin.setMenuid(jkfwMenu.getMenuId());
            pinyin.setPyzm(py);
            pinyin.setPyzmjx(CommonEnum.PinYinEnum.jianpin.getName());
            dao.insert(pinyin);
        }
    }

    /**
     * @Author lly
     * @param: id
     * @Date 2019/8/26 0026
     * @Description 删除菜单
     */
    @Override
    public void delMenuid(String id) {
        JkfwMenuPinyinExample example = new JkfwMenuPinyinExample();
        example.createCriteria().andMenuidEqualTo(id);
        dao.deleteByExample(example);
    }
}
